package service.impl;

import dao.SysRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.SysRole;
import service.SysRoleService;

import java.util.List;

@Transactional
@Service("sysRoleService")
@Scope("prototype")
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    /**
     * 根据名称查询角色列表
     *
     * @param name
     * @return
     */
    @Override
    public List<SysRole> selectAll(String name) {
        return sysRoleMapper.selectAll(name);
    }

    /**
     * 添加角色
     *
     * @param sysRole
     * @return
     */
    @Override
    public boolean add(SysRole sysRole) {
        boolean result=false;
        try {
            if(sysRoleMapper.add(sysRole)>0){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 删除角色
     *
     * @param id
     * @return
     */
    @Override
    public boolean delete(int id) {
        boolean result=false;
        try {
            if(sysRoleMapper.delete(id)>0){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 修改角色
     *
     * @param sysRole
     * @return
     */
    @Override
    public boolean update(SysRole sysRole) {
        boolean result=false;
        try {
            if(sysRoleMapper.update(sysRole)>0){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<SysRole> getRoleList() {
        return sysRoleMapper.getRoleList();
    }

    /**
     * 根据id查询角色
     *
     * @param id
     * @return
     */
    @Override
    public SysRole getRoleById(int id) {
        return sysRoleMapper.getRoleById(id);
    }
}
